<template>
  <div class="home-container">
    <div class="banner">
      <h1>甄淘电商</h1>
      <p>发现好物，品质生活</p>
    </div>
    
    <div class="product-grid">
      <el-card v-for="(item, index) in tableData" :key="index" class="product-card" :body-style="{ padding: '0px' }">
        <el-image class="product-image" :src="item.image" fit="cover" />
        <div class="product-info">
          <h3 class="product-name">{{ item.productName }}</h3>
          <div class="product-price">¥{{ item.price }}</div>
          <div class="product-stock">库存: {{ item.stock }}</div>
          <p class="product-desc">{{ item.description }}</p>
          <el-button type="primary" @click="show(item.id)" class="detail-btn">查看详情</el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import {ref} from "vue";
import {list} from "@/assets/list.js";
import router from "@/router/index.js";

const tableData=ref([])
function getList() {
  list().then(res => {
    tableData.value = res.data
    console.log(res.data)
  })
}
getList()
function show(id){
  router.push({path:"/show",query:{id:id}})
}
</script>

<style scoped>
.home-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.banner {
  text-align: center;
  padding: 40px 0;
  background: linear-gradient(135deg, #1890ff 0%, #36cfc9 100%);
  color: white;
  margin-bottom: 30px;
  border-radius: 8px;
}

.banner h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
}

.banner p {
  font-size: 1.2em;
  opacity: 0.9;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding: 20px 0;
}

.product-card {
  transition: all 0.3s ease;
  border-radius: 8px;
  overflow: hidden;
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.product-info {
  padding: 15px;
}

.product-name {
  margin: 0;
  font-size: 1.1em;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-price {
  color: #f56c6c;
  font-size: 1.2em;
  font-weight: bold;
  margin: 10px 0;
}

.product-stock {
  color: #67c23a;
  font-size: 0.9em;
  margin-bottom: 5px;
}

.product-desc {
  color: #666;
  font-size: 0.9em;
  margin: 10px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.detail-btn {
  width: 100%;
  margin-top: 10px;
}
</style>
